package collection;

/**
 * List提供了一对重载的add和remove方法
 */
import java.util.ArrayList;
import java.util.List;

public class ListDemo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println(list);
        /*
        * void add(int index,E element)
        * 讲给定元素插入到指定位置
        *
        * */
        //[one two three six four five]
        list.add(3,"six");
        System.out.println(list);

        /*E remove(int index)
        删除并返回指定位置的元素
        * */

        //[one two six four five]
        String old = list.remove(2);
        System.out.println(list);
        System.out.println("被删除的元素是："+old);


    }
}
